<div>
    <?php
    $permissions = $sf_data->getRaw('permissions');
    foreach ($modules as $modulo) :
        $mcs = $modulo->ygmPerModuleCredential;
        ?>
        <div>
            <h2> <?php echo $modulo->getName(); ?> </h2>    
            <?php
            foreach ($mcs as $mc) :
                $permission = Doctrine_Core::getTable('sfGuardPermission')
                        ->find($mc->getPermissionId());
                if (in_array(Array($id_ori_nome => $id_ori, "permission_id" => $mc->getPermissionId()), $permissions)) :
                    $display_on = "display: block";
                    $display_off = "display: none";
                else:
                    $display_on = "display: none";
                    $display_off = "display: block";
                endif;
                ?>
                <div style="float: left; width: 60px">
                    <div id="div<?php echo $permission->getId(); ?>" style="float: left; width: 60px; text-align: center; <?php echo $display_on ?>">
                        <?php
                        echo jq_link_to_remote(image_tag('../uploads/credential/' . $mc->Credential->getImagen(), 'alt=foo size=16x16') . '<br>' . $mc->Credential->getName(), array(
                            'url' => '',
                            'complete' => 'setPermission("' . $nomeField . '", ' . $permission->getId() . ')'
                        ));
                        ?> 
                    </div>
                    <div id="div<?php echo $permission->getId(); ?>_off" style="float: left; width: 60px; text-align: center; <?php echo $display_off ?>">
                        <?php
                        $nomeImagem = explode('.', $mc->Credential->getImagen());
                        echo jq_link_to_remote(image_tag('../uploads/credential/' . $nomeImagem[0] . '_off.png', 'alt=foo size=16x16') . '<br>' . $mc->Credential->getName(), array(
                            'url' => '',
                            'complete' => 'setPermission("' . $nomeField . '", ' . $permission->getId() . ')'
                        ));
                        ?>
                    </div>
                </div>
                <?php
            endforeach;
            ?>
        </div>
        <div style="clear: both"></div>
        <?php
    endforeach;
    ?>
</div>
